package com.etop.jansing.dao;

import com.etop.jansing.entities.User;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by jansing on 2015/10/25.
 */
@Repository("userDao")
public class UserDao extends BaseDao<User> {

    public User getByUsername(String username) {
        Session session = getSession();
        return (User) session.createQuery("from User u where u.username=:username and u.valid=true")
                .setString("username", username)
                .uniqueResult();
    }

    public List<User> list() {
        Session session = getSession();
        return session.createQuery("from User u where u.valid=true").list();
    }
}
